package com.xiaoyu.lanling.feature.mission.model

import `in`.srain.cube.request.JsonData
import androidx.annotation.StringDef
import com.xiaoyu.base.utils.extensions.dp
import com.xiaoyu.lanling.feature.mission.viewholder.MissionViewHolderManager
import com.xiaoyu.lanling.media.image.ImageLoadParam

class MissionItem(jsonData: JsonData) : MissionBaseItem() {

    companion object {
        const val ACTION_ROUTE = "route"
        const val ACTION_CHECK_IN = "checkIn"

        const val STATUS_COMPLETE = "COMPLETE"
        const val STATUS_PENDING = "PENDING"
    }

    @StringDef(ACTION_ROUTE, ACTION_CHECK_IN)
    annotation class TaskActionDef

    @StringDef(STATUS_COMPLETE, STATUS_PENDING)
    annotation class TaskStatusDef


    val title = jsonData.optString("title")
    val icon = jsonData.optString("icon")
    val desc = jsonData.optString("desc")
    val awardDesc = jsonData.optString("awardDesc")
    val status = jsonData.optString("status")
    val action = jsonData.optString("action")
    val url = jsonData.optString("url")
    val text = jsonData.optString("text")
    val payload = jsonData.optString("payload")
    val imageParam = ImageLoadParam.newBuilder().setUrl(icon).setWidth(40.dp.toInt()).build()
    val isCompleted = status == STATUS_COMPLETE

    override fun getViewType(): Int {
        return MissionViewHolderManager.TYPE_MISSION
    }
}